using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using WPFTemplateLib.WpfConverters.Core;

namespace WPFTemplateLib.WpfConverters
{
	/// <summary>
	/// [转换器] 布尔值转为显示模式
	/// </summary>
	public class BoolToVisibilityConverter : ValueConverterBase
	{
		/// <summary>
		/// 是否翻转判断
		/// </summary>
		public bool IsReverse { get; set; }

		/// <summary>
		/// 不显示时是否使用 Hidden 模式
		/// </summary>
		public bool IsUseHidden { get; set; }

		public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			bool boolValue = false;
			switch(value)
			{
				case true:
					boolValue = true;
					break;
				case false:
				default:
					boolValue = false;
					break;
			}

			if(IsReverse)
			{
				boolValue = !boolValue;
			}

			return boolValue ? Visibility.Visible : (IsUseHidden ? Visibility.Hidden : Visibility.Collapsed);
		}

		public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return Binding.DoNothing;
		}
	}
}
